export const state = () => ({
    collapse: false,
    title: '',
    pageList: [], // 栏目列表
    token: '', // token
    userInfo: '', // 用户信息
})

export const mutations = {
    UPDATE_COLLAPSE_STATUS(state, status) {
        if (status == null) {
            state.collapse = !state.collapse;
        } else {
            state.collapse = status;
        }
    },
    UPDATE_TITLE(state, title) {
        state.title = title
    },
    SET_PAGE_LIST(state, data) {
        state.pageList = data
    },
    SET_TOKEN(state, token) {
        if (token) {
            state.token = token
        } else {
            state.token = ''
        }
    },
    SET_USER_INFO(state, userInfo) {
        if (userInfo) {
            state.userInfo = userInfo
        } else {
            state.userInfo = ''
        }
    },
}

export const actions = {

    async getInitData({ commit }) {
        const [pages] = await Promise.all([
            this.$axios.$get('/column/list').catch(err => err)
        ])

        commit('SET_PAGE_LIST', pages.data.list)
    },

    async nuxtServerInit({ dispatch }) {
        await dispatch('getInitData');
    }
}